package com.qf.web;

import com.alibaba.fastjson.JSON;
import com.qf.pojo.R;
import com.qf.service.StudentService;
import com.qf.service.impl.StudentServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @date 2022/3/29
 * @desc  ajax方式的删除
 */
@WebServlet("/deleteStudent2")
public class DeleteStudent2Servlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
       this.doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {


        String id = req.getParameter("id");

        StudentService studentService = new StudentServiceImpl();

        int result = studentService.deleteStudentById(Integer.parseInt(id));

        if(result==1){
            System.out.println("删除成功");

            R r = new R(200,"true",null);

            String s = JSON.toJSONString(r);
            resp.getWriter().println(s);

        }
    }
}
